const url = require('url');
const querystring = require('querystring');
function bodyParser(req,res,next) {
    if(req.method == 'GET') {
        var {query} = url.parse(req.url);
        req.body = querystring.parse(query);
        next();
    }
    if(req.method == 'POST') {
        var str = '';
        req.on('data',(chunk) => {
            str += chunk;
        })
        req.on('end',() => {
            req.body = JSON.parse(str);
            next();
        })
    }
}

module.exports = bodyParser;